import storage from '@system.storage';
import Config from './config.js';

// abilityType: 0-Ability; 1-Internal Ability
const ABILITY_TYPE_EXTERNAL = 0;
const ABILITY_TYPE_INTERNAL = 1;
// syncOption(Optional, default sync): 0-Sync; 1-Async
const ACTION_SYNC = 0;
const ACTION_ASYNC = 1;

const PLAY_SOUND = 10005;

var action = {};
action.bundleName = 'com.acedemo.game2048';
action.abilityName = 'com.acedemo.game2048.SoundAbility';
action.abilityType = ABILITY_TYPE_INTERNAL;
action.syncOption = ACTION_SYNC;

export default {
    /**
     * 保存游戏数据
     */
    async playSound(data) {
        var actionData = {
            type: "PLAY_SOUND",
            value: data,
        };
        action.messageCode = PLAY_SOUND;
        action.data = actionData;
        var result = await FeatureAbility.callAbility(action);
        var ret = JSON.parse(result);
        if (ret.code == 0) {
            console.info('===playSound result is:' + JSON.stringify(ret.result));
        } else {
            console.error('===playSound error code:' + JSON.stringify(ret.code));
        }
    },
}